package com.wyj.utils

import java.util.regex.Pattern

object PatternUtils {
    //只是校验手机号
    @JvmStatic
    fun isTel(tel: String?): Boolean {
        return if (isNullOrEmpty(tel)) false else Pattern.compile("^1[3-9]\\d{9}$").matcher(tel.trim()).find()
    }

    //校验手机号和固化
    @JvmStatic
    fun isPhone(phone: String?): Boolean {
        return if (isNullOrEmpty(phone)) false else Pattern.compile("^((\\d{3,4}\\-?)?\\d{7,8})|(1[3-9]\\d{9})$").matcher(phone.trim()).find()
    }

    @JvmStatic
    fun isDate(date: String?): Boolean {
        return if (isNullOrEmpty(date)) false else Pattern.compile("^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$")
            .matcher(date.trim()).find()
    }

    @JvmStatic
    fun isEmail(email: String?): Boolean {
        return if (isNullOrEmpty(email)) false else Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+\$").matcher(email.trim()).find()
    }

    @JvmStatic
    fun isIp(ip: String?): Boolean {
        return if (isNullOrEmpty(ip)) false else Pattern.compile("^((25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\$").matcher(ip.trim()).find()
    }

    @JvmStatic
    fun isMac(mac: String?): Boolean {
        return if (isNullOrEmpty(mac)) false else Pattern.compile("^([0-9A-Fa-f]{2}(\\-|:)?){5}[0-9A-Fa-f]{2}\$").matcher(mac.trim()).find()
    }
}
